package com.example.thirdhomework

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class ThirdActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_third)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        val confirm: Button = findViewById(R.id.confirm)// 获取 confirm 按钮视图
        val editText: EditText = findViewById(R.id.editText)// 获取 editText 编辑文本视图
        confirm.setOnClickListener {// 设置 confirm 按钮点击监听器
            val intent = Intent()// 创建一个新的 Intent
            intent.putExtra("SECOND_MSG", editText.text.toString())// 将编辑文本的内容作为额外信息传递
            setResult(2, intent)// 设置结果码和 Intent
            finish() // 结束当前活动
        }
    }
}